<template>
	<div>
		<el-card shadow="hover">
			<div class=" mb15">
				<el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="100px">
					<el-row>
						<el-col :span="6" class="colBlock">
							<el-form-item label="申请时间" prop="dateRange">
								<el-date-picker v-model="tableData.dateRange" type="datetimerange" size="default"
									style="width: 300px" range-separator="-" start-placeholder="开始日期"
									end-placeholder="结束日期"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="电话号码" prop="phone">
								<el-input v-model="tableData.param.phone" placeholder="请输入电话号码" clearable
									@keyup.enter.native="getList" />
							</el-form-item>
						</el-col>
						<el-col :span="6" >
							<el-form-item label="状态" prop="status">
								<el-select v-model="tableData.param.status" placeholder="请选择平台卡状态" clearable>
									<el-option v-for="dict in dictionary.list1" :key="dict.value" :label="dict.label"
										:value="dict.value" />
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="6" >
							<el-form-item>
								<el-button type="primary" @click="getList"><el-icon>
										<Search />
									</el-icon>搜索</el-button>
								<el-button @click="resetQuery(queryRef)"><el-icon>
										<Refresh />
									</el-icon>重置</el-button>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</div>
			<el-table v-loading="loading" :data="tableData.data">
				<el-table-column label="电话号码" align="center" prop="phone" min-width="100px" />
				<el-table-column label="注销原因" align="center" prop="reason" min-width="100px" />
				<el-table-column label="状态" align="center" prop="statusTxt" min-width="100px" />
				<el-table-column label="备注" align="center" prop="remark" min-width="100px" />
				<el-table-column label="申请时间" align="center" prop="createTime" :formatter="formatDateTime"
					min-width="100px" />
				<el-table-column label="操作" v-if="permissionStore.isPermissionsBtn('010003001')"  align="center" class-name="small-padding" min-width="200px" fixed="right">
					<template #default="scope" >
							<el-button type="primary" :disabled="scope.row.status!='LV1_AUDIT'" v-if="permissionStore.isPermissionsBtn('010003001')"  link @click="handleAudit(scope.row)"><el-icon>
								<EditPen />
							</el-icon>审核</el-button>
					</template>
				</el-table-column>
			</el-table>
			<pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNumber"
				v-model:limit="tableData.param.pageLength" @pagination="getList" />
				
		</el-card>
		<audit ref="auditRef" @getList="getList"></audit>
	</div>
</template>
<script lang="ts">
import { writeoffListApi } from '@/api/numberManage/writeoff';
import { toRefs, reactive, onMounted, ref, defineComponent, computed, getCurrentInstance, toRaw } from 'vue';
import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
import { usePermissionStore } from '@/store/modules/permission'
import { formatDateTime, updateParamsWithDateRange } from '@/utils/index'
import audit from './components/audit.vue'
export default defineComponent({
	name: 'writeoffList', //申请注销列表
	components:{audit},
	setup() {
		const { proxy } = <any>getCurrentInstance();
		const loading = ref(false);
		const queryRef = ref();
		const permissionStore = usePermissionStore()
		const auditRef = ref()
		
		const state = reactive({
			dictionary: {
				"LV1_AUDIT": "客户经理待审核",
				"LV2_AUDIT": "待审核人员审核",
				"LV1_REFUSE": "客户经理拒绝",
				"LV2_REFUSE": "审核人员拒绝",
				"WAIT": "等待注销",
				"WRITE_OFF": "注销",
				list1: [
					{
						value: 'LV1_AUDIT',
						label: '客户经理待审核'
					},
					{
						value: 'LV2_AUDIT',
						label: '待审核人员审核'
					},
					{
						value: 'LV1_REFUSE',
						label: '客户经理拒绝'
					},
					{
						value: 'LV2_REFUSE',
						label: '审核人员拒绝'
					},
					{
						value: 'WAIT',
						label: '等待注销'
					},
					{
						value: 'WRITE_OFF',
						label: '注销'
					}
				]
			},
			tableData: {
				data: [],
				total: 0,
				loading: false,
				dateRange: [],
				param: {
					pageNumber: 1,
					pageLength: 10,
					beginTime: '',
					endTime: '',
					phone:'',
					status:'',
				},
			},
		});
		// 页面加载时
		onMounted(() => {
			initTableData();
		});
		// 初始化表格数据
		const initTableData = () => {
			getList();
		};
		/** 重置按钮操作 */
		const resetQuery = (formEl: FormInstance | undefined) => {
			if (!formEl) return;
			formEl.resetFields();
			state.tableData.dateRange=[]
			getList();
		};
		// 获取列表数据
		const getList = () => {
			loading.value = true;
			const obj = updateParamsWithDateRange(state.tableData.dateRange)
			Object.assign(state.tableData.param, obj);
			if(!state.tableData.param.status)state.tableData.param.status=null
			writeoffListApi(state.tableData.param).then((res: any) => {
				let list = res?.data.list ?? [];
				state.tableData.data = list.map(item => {
					item.statusTxt = state.dictionary[item.status]
					return item
				})
				console.log(state.tableData.data);
				state.tableData.total = res.data.total;
				loading.value = false;
			});
		};
		const handleAudit = (row) => {
			auditRef.value.openDialog(row)
		};

		return {
			proxy,
			loading,
			queryRef,
			auditRef,
			resetQuery,
			getList,
			handleAudit,
			permissionStore,
			formatDateTime,
			...toRefs(state),
		};
	},
});
</script>
<style lang="scss" scoped>
.colBlock {
	display: block;
}

.colNone {
	display: none;
}
</style>
